package com.cloudkinto.service.progress.impl;

import cn.hutool.json.JSONUtil;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.cloudkinto.bo.progress.ProgressQueryBo;
import com.cloudkinto.dao.ProgressDao;
import com.cloudkinto.entity.ProgressDo;
import com.cloudkinto.service.progress.ProgressService;
import com.cloudkinto.vo.progress.ProgressVo;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 业务进度表 service实现类
 * </p>
 *
 * @author long
 * @since 2024-11-01
 */
@Service
public class ProgressServiceImpl extends ServiceImpl<ProgressDao, ProgressDo> implements ProgressService {

    @Override
    public List<ProgressVo> getProgress(ProgressQueryBo bo) {
        List<ProgressDo> doList = this.lambdaQuery()
                .eq(ProgressDo::getType, bo.getBizType().getTypeCode())
                .eq(ProgressDo::getBizNumber, bo.getBizNumber())
                .orderByAsc(ProgressDo::getSort)
                .list();
        return JSONUtil.toList(JSONUtil.toJsonStr(doList), ProgressVo.class);
    }

    @Override
    public void batchInsert(List<ProgressDo> progressDoList) {
        if (progressDoList.isEmpty()) {
            return;
        }
        baseMapper.insertBatch(progressDoList);
    }


    @Override
    public void deleteByIds(List<Long> bigNumberList, Integer type) {
        if (bigNumberList.isEmpty()) {
            return;
        }
        this.lambdaUpdate()
                .eq(ProgressDo::getType, type)
                .in(ProgressDo::getBizNumber, bigNumberList)
                .remove();
    }
}
